package utils;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class UpdateConversionTimeUtils {
    static SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
    static SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
    static DecimalFormat decimalFormat = new DecimalFormat("##.00");

    public static Double conversionTime(Date endContract, Date beginContract) {
        double month = (Double.parseDouble(yearFormat.format(endContract)) - Double.parseDouble(yearFormat.format(beginContract))) * 12
                + (Double.parseDouble(monthFormat.format(endContract)) - Double.parseDouble(monthFormat.format(beginContract)));
        return Double.parseDouble(decimalFormat.format(month / 12));
    }
}
